/*
 * @Author: 王朋坤
 * @Date: 2021-08-13 11:01:10
 * @LastEditTime: 2021-09-09 15:05:10
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /cesium-vue-cli/cesium-demo/vue.config.js
 */

// The path to the CesiumJS source code
const cesiumSource = 'node_modules/cesium/Source';
const cesiumWorkers = '../Build/Cesium/Workers';
const path = require('path');
const webpack = require("webpack");
const CopyPlugin = require("copy-webpack-plugin");

module.exports = {
    configureWebpack: {
        output: {
            sourcePrefix: ' ',
        },
        amd: {
            toUrlUndefined: true,
        },
        plugins: [
            // Copy Cesium Assets, Widgets, and Workers to a static directory
            new CopyPlugin({ patterns: [{ from: path.join(cesiumSource, cesiumWorkers), to: 'Workers' }] }),
            new CopyPlugin({ patterns: [{ from: path.join(cesiumSource, 'Assets'), to: 'Assets' }] }),
            new CopyPlugin({ patterns: [{ from: path.join(cesiumSource, 'Widgets'), to: 'Widgets' }] }),
            new CopyPlugin({ patterns: [{ from: path.join(cesiumSource, 'ThirdParty'), to: 'ThirdParty'}]}),
            new webpack.DefinePlugin({
                // Define relative base path in cesium for loading assets
                CESIUM_BASE_URL: JSON.stringify("")
            }),
        ],
        module: {
            unknownContextCritical: false,
            unknownContextRegExp: /\/cesium\/cesium\/Source\/Core\/buildModuleUrl\.js/,
        },
    },
    devServer: {
        proxy: {
            // 遥感、地形、3Dtitle切片等静态资源
            '/output': {
                target: 'http://localhost:80',
                ws: true,
                changeOrigin: true
            },
        }
    }
};